package cn.org.xuanguang.kepler.hormos.rdb.dml.warrper;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class JavaBeanListMapper<T extends Serializable> implements ResultWrapper<T, List<T>> {


    private ResultWrapper<T, ?> wrapper;

    private final List<T> resultList = new ArrayList<>();


    public JavaBeanListMapper(ResultWrapper<T, ?> wrapper) {
        this.wrapper = wrapper;
    }

    @Override
    public T newRowInstance() {
        // 复用单对象的实例化
        return wrapper.newRowInstance();
    }

    @Override
    public void wrapColumn(ColumnWrapperContext<T> context) {
        wrapper.wrapColumn(context);
    }

    @Override
    public boolean completedWrapRow(T result) {
        resultList.add(result);
        return wrapper.completedWrapRow(result);
    }

    @Override
    public void completedWrap() {
        wrapper.completedWrap();
    }

    @Override
    public List<T> getResult() {
        return resultList;
    }
}
